package beanstao.util.table;

import beanstao.util.log.ILog;
import beanstao.util.log.LogHelper;

/**
 * 表头信息
 * 
 * @author beanstao@google.com 
 */
public abstract class Meta implements ILog
{
	private String name;
	private Class<?> klass = Long.class;
	private boolean canNull = true;
	private int length = 16;
	private Object defalut = 0;

	private int slice = -1;
	private String hour = "24";

	public int getSlice()
	{
		return slice;
	}

	public String getHour()
	{
		return hour;
	}

	public Meta(String name, String hour)
	{
		this.hour = hour;
		this.name = name + hour;
	}

	public Meta(String name, int slice)
	{
		this.slice = slice;
		this.name = name + slice;
	}

	public Meta(String name)
	{
		this.name = name;
	}

	public Meta(String name, boolean canNull)
	{
		this.name = name;
		this.canNull = canNull;
	}

	public Meta(String name, boolean canNull, int length)
	{
		super();
		this.name = name;
		this.canNull = canNull;
		this.length = length;
	}

	public Meta(String name, boolean canNull, int length, Class<?> klass, Object defalut)
	{
		super();
		this.name = name;
		this.klass = klass;
		this.canNull = canNull;
		this.length = length;
		this.defalut = defalut;
	}

	protected void setName(String name, int slice)
	{
		this.name = name + slice;
	}

	protected void setName(String name, String hour)
	{
		this.name = name + hour;
	}

	protected abstract String getCHSBaseName();

	public abstract String getCHSName();

	/**
	 * @return 列的名字
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * @return 列的数据类型
	 */
	public Class<?> getKlass()
	{
		return klass;
	}

	/**
	 * @return 该列数据是否能够为空
	 */
	public boolean isCanNull()
	{
		return canNull;
	}

	/**
	 * @return 数据长度
	 */
	public int getLength()
	{
		return length;
	}

	/**
	 * @return 如果未传值的话的默认值
	 */
	public Object getDefalut()
	{
		return defalut;
	}

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (this.getClass() != obj.getClass())
			return false;
		Meta other = (Meta) obj;
		if (name == null)
		{
			if (other.name != null)
				return false;
		}
		else if (!name.equals(other.name))
			return false;
		return true;
	}

	@Override
	public String toString()
	{
		StringBuilder builder = new StringBuilder();
		builder.append("Meta [name=").append(name).append("]");
		return builder.toString();
	}

	// ============================

	@Override
	public void logDebug(Object message)
	{
		LogHelper.logDebug(this, message);
	}

	@Override
	public void logDebug(Object message, Throwable t)
	{
		LogHelper.logDebug(this, message, t);
	}

	@Override
	public void logError(Object message)
	{
		LogHelper.logError(this, message);
	}

	@Override
	public void logError(Object message, Throwable t)
	{
		LogHelper.logError(this, message, t);
	}

	@Override
	public void logInfo(Object message)
	{
		LogHelper.logInfo(this, message);
	}

	@Override
	public void logInfo(Object message, Throwable t)
	{
		LogHelper.logInfo(this, message, t);
	}

	@Override
	public void logWarn(Object message)
	{
		LogHelper.logWarn(this, message);
	}

	@Override
	public void logWarn(Object message, Throwable t)
	{
		LogHelper.logWarn(this, message, t);
	}
}
